package cn.com.idmy.mq;

import cn.com.idmy.mq.model.MqDest;
import cn.com.idmy.mq.model.MqSendResult;
import cn.com.idmy.mq.model.MqTopic;
import cn.com.idmy.mq.model.enums.MqDelayLevel;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class MqUtil {
    static IMqProducer producer;

    private static void checkProducer() {
        if (producer == null) {
            throw new NullPointerException("未开启发送消息功能");
        }
    }

    public static MqSendResult send(MqDest dest) {
        return send(dest, dest);
    }

    public static MqSendResult send(MqDest dest, Object body) {
        return send(dest, dest.getMqTag(), dest.getMqKey(), body);
    }

    public static MqSendResult send(MqTopic topic, String tag, String key, Object body) {
        checkProducer();
        return producer.send(topic.getMqTopic(), tag, key, body);
    }

    public static MqSendResult send(String tag, String key, Object body) {
        checkProducer();
        return producer.send(null, tag, key, body);
    }

    public static MqSendResult sendOrderly(MqDest dest) {
        return sendOrderly(dest, dest);
    }

    public static MqSendResult sendOrderly(MqDest dest, Object body) {
        return sendOrderly(dest, dest.getMqTag(), dest.getMqKey(), body);
    }

    public static MqSendResult sendOrderly(MqTopic topic, String tag, String key, Object body) {
        checkProducer();
        return producer.sendOrderly(topic.getMqTopic(), tag, key, body, null);
    }

    public static MqSendResult sendOrderly(String tag, String key, Object body) {
        checkProducer();
        return producer.sendOrderly(null, tag, key, body, null);
    }

    public static MqSendResult sendDelay(MqDest dest, Object body, MqDelayLevel level) {
        return sendDelay(dest, dest.getMqTag(), dest.getMqKey(), body, level);
    }

    public static MqSendResult sendDelay(MqTopic topic, String tag, String key, Object body, MqDelayLevel level) {
        checkProducer();
        return producer.sendDelay(topic.getMqTopic(), tag, key, body, level);
    }

    public static MqSendResult sendDelay(String tag, String key, Object body, MqDelayLevel level) {
        checkProducer();
        return producer.sendDelay(null, tag, key, body, level);
    }
}
